package top.superflow.db.orientdb

import com.orientechnologies.orient.`object`.db.{ODatabaseObjectPool, OrientDBObject}
import top.superflow.db.api.{DBConfiguration, DBConfigurationValidator, DBPool}

class OrientDBPool ( dbConfig : DBConfiguration)extends DBPool with DBConfigurationValidator{
  
  validate(dbConfig)

  import com.orientechnologies.orient.core.db.{OrientDB, OrientDBConfig}

  private val orientDB = new OrientDB(dbConfig.getUrl, dbConfig.getUsername, dbConfig.getPassword, OrientDBConfig.defaultConfig)

  private val currentConfig = dbConfig

  val orientDBO = new OrientDBObject(orientDB)
  private val targetPool = new ODatabaseObjectPool(orientDBO, dbConfig.getDBName, dbConfig.getUsername, dbConfig.getPassword)



//  this.targetPool.setAutoCreate(true)
  
  
  def acquire : OrientConnection = {
    new OrientConnection(targetPool.acquire())
  }
  
  def getUrl = {
    currentConfig.getUrl
  }
  
  def getUsername = {
    currentConfig.getUsername
  }
  
  def getPassword = {
    currentConfig.getPassword
  }
  
}